<template>
	<div class="login">
		<input type="text" name="" id="" value="" v-model="name" placeholder="账号"/>
		<br>
		<br>
		<input type="password" name="" v-model="password" placeholder="密码"/>
		<br>
		<br>
		<button type="button" @click="login()">登录</button>
	</div>
</template>

<script>
	import axios from 'axios'
	export default {
		data(){
			return{
				name:"",
				password:""
				
			}
		},
		methods:{
			login(){
				var that=this;
			axios.get("http://localhost:8080/check?name="+this.name+"&password="+this.password)
			.then(function (res) {
				that.$router.push("/index");
				var user=res.data.data;
				if(user!=null){
					//vuex数据保存
					that.$store.commit('login',user);
					alert("登录成功");
					that.$router.push("/index");
				}
				else{
					alert("❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌❌");
					that.name="";
					that.password="";
					return false;
			}
			})
			.catch(function (err) {
				console.log(err);
			})
	}
	},
	}
</script>

<style scoped>
	.login{
		text-align: center;
		font-size: 20px;
		margin-top: 10%;
	}
	input{
		height: 30px;
	}
	button{
		height: 30px;
	}
</style>